<%-- 
    Document   : user_regist_bean
    Created on : Jan 4, 2013, 3:50:10 PM
    Author     : ngoc.phan
--%>

<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <jsp:useBean id="userBean" class="noah.UserBean" scope="session">
        </jsp:useBean>
        <%
            Connection connection = null;
            String url = "jdbc:mysql://localhost:3306/";
            String dbName = "english";
            String driverName = "com.mysql.jdbc.Driver";
            String userName = "root";
            String password = "123456";
            PreparedStatement pstmt = null;
            try {
                Class.forName(driverName).newInstance();
                connection = DriverManager.getConnection(url + dbName, userName, password);
                pstmt = connection.prepareStatement("insert into user(userName,password,email) values(?,?,?)");
                pstmt.setString(1, userBean.getUserName());
                pstmt.setString(2, userBean.getPassword());
                pstmt.setString(3, userBean.getEmail());
                pstmt.executeUpdate();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                pstmt.close();
                connection.close();
            }
            session.removeAttribute("userBean");
        %>
        Insert new user by using Java Bean<br/>
        <a href="registrationHTML.html">Back</a>
    </body>
</html>
